package com.example.shushiyunsst.fragment.main.home.child.new_sale.chlid.goods.widget

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.view.animation.AnimationUtils
import android.widget.FrameLayout
import com.example.library_common.album.view.AlbumFolderLayoutToggleListener
import com.example.shushiyunsst.R

class GoodsFolderLayout
@JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) :
    FrameLayout(context, attrs, defStyleAttr) {

    private var albumFolderMaskView: View

    private var albumFolderPopupMenuViews: View

    private var isShowing = false

    private var toggleListener: GoodsFolderLayoutToggleListener?=null

    fun setToggleListener(toggle:GoodsFolderLayoutToggleListener){
        this.toggleListener=toggle
    }

    init {
        inflate(context, R.layout.goods_folder_layout, this)
        albumFolderMaskView = findViewById(R.id.albumFolderMaskView)
        albumFolderPopupMenuViews = findViewById(R.id.albumFolderPopupMenuViews)
        hide()
        albumFolderMaskView.setOnClickListener { hide() }
    }

    fun getAlbumFolderPopupMenuViews():View{
        return albumFolderPopupMenuViews
    }

    private fun show() {
        albumFolderPopupMenuViews.visibility = VISIBLE
        albumFolderPopupMenuViews.animation =
            AnimationUtils.loadAnimation(context, R.anim.dd_mask_drop_in)

        albumFolderMaskView.visibility = VISIBLE
        albumFolderMaskView.animation =
            AnimationUtils.loadAnimation(context, R.anim.dd_mask_in)

        isShowing = true

        toggleListener?.onToggle()
    }

    private fun hide() {

        albumFolderPopupMenuViews.visibility = GONE
        albumFolderPopupMenuViews.animation =
            AnimationUtils.loadAnimation(context, R.anim.dd_mask_drop_out)

        albumFolderMaskView.visibility = GONE
        albumFolderMaskView.animation =
            AnimationUtils.loadAnimation(context, R.anim.dd_mask_out)

        isShowing = false

        toggleListener?.onToggle()

    }

    fun toggle() {
        if (isShowing) {
            hide()
        } else {
            show()
        }
    }

    fun isOnShowIng() = isShowing


}